<template>
    <div class="login">
        <el-row style="width:100%;" justify="center">
            <el-col :lg="8" :xs="22" :sm="12" :md="12">
                <el-card class="card">
                    <h2 style="color:white;">DevCat Admin</h2>
                    <el-form>
                        <el-form-item label="">
                            <el-input v-model="username" placeholder="用户名" clearable prefix-icon="User"></el-input>
                        </el-form-item>
                        <el-form-item label="">
                            <el-input @keypress.enter="login" v-model="password" show-password type="password" placeholder="密码" clearable prefix-icon="Lock">
                            </el-input>
                        </el-form-item>
                        <el-form-item label="">
                            <div class="loginBtn">
                                <el-button @click="register" style="width:48%;">注册</el-button>
                                <el-button @click="login" type="primary" style="width:48%">登录</el-button>
                            </div>
                        </el-form-item>
                    </el-form>
                </el-card>
            </el-col>
        </el-row>
        <div class="footer">测试版本: Beta-v-0.0.1</div>
    </div>
</template>
<script>
import { login, register } from '../js/api.js'
import 'element-plus/es/components/message/style/css'
import { ElMessage } from 'element-plus'
export default {
    name: 'Login',
    data() {
        return {
            username: '',
            password: ''
        }
    },
    methods: {
        login() {
            if (this.check()) {
                login({ username: this.username, password: this.password }).then(res => {
                    if (!res.status) ElMessage({ message: res.msg, type: res.status ? 'success' : 'error' });
                    if (res.status) {
                        this.$router.push('/'); //登录成功他跳转到主页路由
                        localStorage.setItem('auth-system-login', true)
                        localStorage.setItem('auth-system-username',res.data)
                    }
                });
            }

        },
        register() {
            if (this.check()) {
                register({ username: this.username, password: this.password }).then(res => { ElMessage({ message: res.msg, type: res.status ? 'success' : 'error' }) });
            }
        },
        check() {
            if (this.username == '' || this.password == '') {
                ElMessage({ message: '请输入正确的用户名和密码', type: 'error' });
                return false;
            }
            return true;
        }
    },
    mounted() {
    }
}
</script>
<style scoped>
.login {
    display: flex;
    align-items: center;
    height: 100vh;
    /* background-color: #333333; */
    background: white;
    background-image: linear-gradient(125deg, #799def, #6DD5FA, #2980B9, #799def);
    background-size: 400%;
    background-image: url(../assets/login.jpeg);
    background-size: 100% 100%;
    filter: blur(0px);
    /* animation: bganimation 15s infinite; */
}

.card {
    background-color: rgba(0, 0, 0, 0.4);
    border-color: transparent;
}

.loginBtn {
    width: 100%;
    display: flex;
    justify-content: space-between;
}
.footer{
    position: absolute;
    bottom: 0;
    z-index: 1000;
    color: white;
    width: 100%;
    text-align: right;
    font-size: 13px;
    opacity: 0.8;
}
</style>
